package com.luke.springcloud.service.impl;

import com.luke.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import javax.annotation.Resource;
import java.util.UUID;

@EnableBinding(Source.class)//表示是数据源
public class MessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output; //名称对应yml文件的通道的名称

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        Message<String> message = MessageBuilder.withPayload(serial).build();
        output.send(message);
        System.out.println("发送数据，serial:"+serial);
        return serial;
    }

}
